/*--------------------------------------------------------------------------
 *
 * 	You may freely copy, distribute, and reuse the code in this example.
 * 	SHL Systemhouse disclaims any warranty of any kind, expressed or  
 *	implied, as to its fitness for any particular use.
 *
 *
 *	AppController
 *
 *	Inherits From:		NSObject
 *
 *	Conforms To:		None
 *
 *	Declared In:		AppController.h
 *
 *
 *------------------------------------------------------------------------*/
#import "AppController.h"
#import "DataSource.h"
#import "Motorcycle.h"
#import "ScrollViewExtensions.h"
#import <eointerface/EOController.h>
#import <foundation/NSString.h>

#define print_trace [self console: [NSString stringWithFormat:\
@"EOCONTROLLER  %s\n", sel_getName(_cmd)]]



@implementation AppController

/*--------------------------------------------------------------------------
 *	Cover Methods for EOController Actions
 *------------------------------------------------------------------------*/
- fetch: sender
{
	sequence++;
	print_trace;
	[eoController fetch: sender];
	return self;
}


- insert: sender
{
	sequence++;
	print_trace;
	[eoController insert: sender];
	return self;
}


- delete: sender
{
	sequence++;
	print_trace;
	[eoController delete: sender];
	return self;
}


- saveToObjects: sender
{
	sequence++;
	print_trace;
	[eoController saveToObjects: sender];
	return self;
}


- saveToDataSource: sender
{
	sequence++;
	print_trace;
	[eoController saveToDataSource: sender];
	return self;
}


- undo: sender
{
	sequence++;
	print_trace;
	[eoController undo: sender];
	return self;
}


/*--------------------------------------------------------------------------
 *	Printing Trace Information
 *------------------------------------------------------------------------*/
- console: (NSString *) aString
{
	static int	lastSequence = 0;
	
	if (sequence == 0) return self;

	if (lastSequence != sequence)
		{
		[console sprintf: "\n"];
		lastSequence = sequence;
		}
		
	[console sprintf: "[%d]  %s", sequence, [aString cString]];
	return self;
}


/*--------------------------------------------------------------------------
 *	Initialization
 *------------------------------------------------------------------------*/
- appDidInit: sender
{
	/* Initialize 'persistentStore' with a couple of objects */
	
	id	object;
	
	object = [dataSource createObject];
	[object setMake: @"Honda"];
	[object setModel: @"CBR 900RR"];
	[object setPrice: @"8999.00"];
	[object setPicture: [NXImage findImageNamed: "CBR900RR"]];
	[dataSource insertObject: object];
	
	object = [dataSource createObject];
	[object setMake: @"Ducati"];
	[object setModel: @"900SS SP"];
	[object setPrice: @"9750.00"];
	[object setPicture: [NXImage findImageNamed: "Ducati900SS"]];
	[dataSource insertObject: object];
	
	[dataSource saveObjects];
	[self fetch: nil];
	return self;
}


@end
